{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 作业一\n",
    "改进 characterglm_api_demo_streamlit.py 的代码，为文生图功能加上风格选项，并在页面上加一个可指定图片风格的选项框。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 2x2 layout\n",
    "with st.container():\n",
    "    col1, col2, col3 = st.columns(3)\n",
    "    with col1:\n",
    "        st.text_input(label=\"角色名\", key=\"bot_name\", on_change=lambda : st.session_state[\"meta\"].update(bot_name=st.session_state[\"bot_name\"]), help=\"模型所扮演的角色的名字，不可以为空\")\n",
    "        st.text_area(label=\"角色人设\", key=\"bot_info\", on_change=lambda : st.session_state[\"meta\"].update(bot_info=st.session_state[\"bot_info\"]), help=\"角色的详细人设信息，不可以为空\")\n",
    "        \n",
    "    with col2:\n",
    "        st.text_input(label=\"用户名\", key=\"user_name\", on_change=lambda : st.session_state[\"meta\"].update(user_name=st.session_state[\"user_name\"]), help=\"用户的名字，默认为用户\")\n",
    "        st.text_area(label=\"用户人设\", key=\"user_info\", on_change=lambda : st.session_state[\"meta\"].update(user_info=st.session_state[\"user_info\"]), help=\"用户的详细人设信息，可以为空\")\n",
    "        \n",
    "    with col3:\n",
    "        st.text_input(label=\"图片风格\", key=\"img_style\", on_change=lambda : st.session_state[\"meta\"].update(img_style=st.session_state[\"img_style\"]), help=\"图片风格，如：二次元风格\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "    # TODO: 加上风格选项\n",
    "    image_prompt = st.session_state[\"meta\"][\"img_style\"] + '。' + image_prompt.strip()"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![1.png](./images/1.png)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![2.png](./images/2.png)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 作业二\n",
    "\n",
    "实现 role-play 对话数据生成工具，要求包含下列功能：  \n",
    "\n",
    "- 基于一段文本（自己找一段文本，复制到提示词就可以了，比如你可以从小说中选取一部分文本，注意文本要用 markdown 格式）生成角色人设，可借助 ChatGLM 实现。\n",
    "- 给定两个角色的人设，调用 CharacterGLM 交替生成他们的回复。\n",
    "- 将生成的对话数据保存到文件中。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![3.png](./images/3.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
